/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Model.Location;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Sony
 */
public class LocationHelper {
    
    Session session;
    public LocationHelper(){
        session = HibernateUtil.getSessionFactory().getCurrentSession();
    }
    
    public List<Location> getAllLocation(){
        List<Location> listLocation = null;
        try {
            org.hibernate.Transaction tx = this.session.beginTransaction();
            Query q = this.session.createQuery("from Location");
            listLocation = (List<Location>)q.list();
        } catch (Exception e) {
        }
        return listLocation;
    }
    
    public void updateLocation(Location l){
        try {
             org.hibernate.Transaction tx = this.session.beginTransaction();
             this.session.save(l);
             tx.commit();
        } catch (Exception e) {
        }
    }
    public void deleteLocation(Location l){
         try {
             org.hibernate.Transaction tx = this.session.beginTransaction();
             this.session.delete(l);
             tx.commit();
        } catch (Exception e) {
        }
    }
}
